package com.oto.service;

import java.util.Collection;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import org.springframework.stereotype.Service;

import com.oto.model.IndexDO;

/**
 * @author xueqiang.mi
 * @since 2011-1-16
 */
@Service
public class IndexService extends BaseService {

	@SuppressWarnings("unchecked")
	public IndexDO getIndex(String key) {
		PersistenceManager pm = PMF.get();
		try {
			Query query = pm.newQuery(IndexDO.class);
			query.setFilter("key == :key");
			Collection<IndexDO> c = (Collection<IndexDO>) query.execute(key);
			if (c != null && !c.isEmpty()) { // 返回查询结果的第一个
				return (IndexDO) c.toArray()[0];
			}
			return null;
		} finally {
			pm.close();
		}
	}
}
